package net.lcheng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.lcheng.commons.utils.PageList;
import net.lcheng.dao.UserAccountDetailsMapper;
import net.lcheng.model.UserAccountDetails;
import net.lcheng.model.UserAccountDetailsExample;
import net.lcheng.service.UserAccountDetailsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * Created by zwr on 2016/7/8 0008.
 */
@Service
public class UserAccountDetailsServiceImpl implements UserAccountDetailsService {
    @Resource
    private UserAccountDetailsMapper mapper;
    @Override
    public int addUserAccountDetails(UserAccountDetails userAccountDetails) {
        return mapper.insert(userAccountDetails);

    }
    @Override
    public PageList<UserAccountDetails> getUserWalletDetailsByUserId(int pageIndex, int pageSize, String userId) {
        PageHelper.startPage(pageIndex,pageSize);
        UserAccountDetailsExample example=new UserAccountDetailsExample();
        example.or().andUserIdEqualTo(userId);
        List<UserAccountDetails> list = mapper.selectByExample(example);
        PageInfo<UserAccountDetails> pageInfo = new PageInfo<>(list);
        PageList<UserAccountDetails> pageList = new PageList<>();
        pageList.list = pageInfo.getList();
        pageList.totalCount = pageInfo.getTotal();
        pageList.totalPage=pageInfo.getPages();
        pageList.pageIndex=pageInfo.getPageNum();
        pageList.pageSize=pageInfo.getPageSize();
        return pageList;
    }
    @Override
    public List<UserAccountDetails> getUserWalletDetailsByUserId(String userId) {
        UserAccountDetailsExample example=new UserAccountDetailsExample();
        example.or().andUserIdEqualTo(userId);
        return mapper.selectByExample(example);
    }
}